<html>
<head><meta charset="utf-8"><title>Op impls for &amp;mut integers · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html">Op impls for &amp;mut integers</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="247049134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247049134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247049134">(Jul 24 2021 at 01:28)</a>:</h4>
<p>I just noticed <a href="https://github.com/rust-lang/rust/issues/46909">#46909</a>. I wanted to check: is the absence of operation implementations for <code>&amp;mut</code> integers deliberate or an oversight? I have trouble believing it's just an oversight, given how long things have been this way...</p>



<a name="247060656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247060656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247060656">(Jul 24 2021 at 07:11)</a>:</h4>
<p>Deliberate as far as I know.</p>



<a name="247112415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247112415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247112415">(Jul 25 2021 at 06:50)</a>:</h4>
<p>Alright. Unless someone says otherwise in the next bit, I'm going to close the issue with "libs says this is the intended behavior".</p>



<a name="247112670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247112670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247112670">(Jul 25 2021 at 06:58)</a>:</h4>
<p>One clarification: I think those impls were deliberately omitted, but that doesn't mean they're something people are strongly opposed to. That would take some discussion to find out. (For my part, I'm mildly opposed but not strongly.)</p>



<a name="247112842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247112842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247112842">(Jul 25 2021 at 07:03)</a>:</h4>
<p><em>nods</em></p>



<a name="247112887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247112887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247112887">(Jul 25 2021 at 07:04)</a>:</h4>
<p>I can mention that it would either need further discussion or an RFC.</p>



<a name="247132120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247132120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247132120">(Jul 25 2021 at 15:53)</a>:</h4>
<p>Exactly.</p>



<a name="247148712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247148712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247148712">(Jul 25 2021 at 22:23)</a>:</h4>
<p>It's already annoying to write the 4 combinations of <code>T</code>/<code>&amp;T</code> operands, and that becomes 9 if you fully expand it with <code>&amp;mut T</code>.</p>



<a name="247149281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247149281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247149281">(Jul 25 2021 at 22:38)</a>:</h4>
<p>Pardon, I'm a bit confused. Where would you have to write them?</p>



<a name="247149364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247149364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247149364">(Jul 25 2021 at 22:41)</a>:</h4>
<p>As far as I know, this would require changing the <code>forward_ref_unop</code>, <code>forward_ref_binop!</code>,  and <code>forward_ref_op_assign!</code> macros, and that's it.</p>



<a name="247149369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247149369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247149369">(Jul 25 2021 at 22:41)</a>:</h4>
<p>They're all in one file.</p>



<a name="247170971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247170971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247170971">(Jul 26 2021 at 07:28)</a>:</h4>
<p>Sure, the macros can do it. My annoyance has mostly been when writing third-party types, where I also end up using macros.</p>



<a name="247170998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247170998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247170998">(Jul 26 2021 at 07:29)</a>:</h4>
<p>It will also multiply in the docs.</p>



<a name="247178554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247178554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247178554">(Jul 26 2021 at 09:09)</a>:</h4>
<p>It feels like this needs to be ergonomic to do, and if it isn't, we should make it ergonomic somehow.</p>



<a name="247178660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247178660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247178660">(Jul 26 2021 at 09:10)</a>:</h4>
<p>This is quite apart from the specific question of whether these specific impls should exist.</p>



<a name="247178877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247178877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247178877">(Jul 26 2021 at 09:13)</a>:</h4>
<p>It's not like Iike I have a solution though. Just pointing out that this seems to be a problem. :)</p>



<a name="247179990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247179990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247179990">(Jul 26 2021 at 09:26)</a>:</h4>
<p>Actually, I do have an idea... but I need to sleep now. I'll post tomorrow. (There's a fair chance it wont work anyway.)</p>



<a name="247304487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247304487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247304487">(Jul 27 2021 at 08:00)</a>:</h4>
<p>The idea was to change the coercion or lookup rules.</p>



<a name="247304516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247304516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247304516">(Jul 27 2021 at 08:01)</a>:</h4>
<p>I had a more specific change in mind last night, but further checking suggests that it's invalid.</p>



<a name="247304573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247304573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247304573">(Jul 27 2021 at 08:02)</a>:</h4>
<p>I do think it's interesting that <code>&lt;&amp;i32 as Add&gt;::add(&amp;1, &amp;mut 2);</code> compiles though. It presumably means that there's a way to do this.</p>



<a name="247305010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247305010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247305010">(Jul 27 2021 at 08:06)</a>:</h4>
<p>Well in that case, the <code>&amp;mut i32</code> is automatically being converted to <code>&amp;i32</code> at the call site, right?</p>



<a name="247306812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247306812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247306812">(Jul 27 2021 at 08:29)</a>:</h4>
<p>Yep!</p>



<a name="247339260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247339260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247339260">(Jul 27 2021 at 14:19)</a>:</h4>
<p>yeah, more coercions happen at function/method call sites than at binary operator subexpressions</p>



<a name="247363712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247363712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247363712">(Jul 27 2021 at 17:22)</a>:</h4>
<p>Well, also, specifying the type seems to help.</p>



<a name="247363754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Op%20impls%20for%20%26mut%20integers/near/247363754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Op.20impls.20for.20.26mut.20integers.html#247363754">(Jul 27 2021 at 17:22)</a>:</h4>
<p>The <code>&lt;&amp;i32 as Add&gt;</code> bit does better than it would without it.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>